<template>
	<view>
		<view class="head">
			<image class="portrait" :src="userHeadPic?userHeadPic:'/static/missing-face.png'"></image>
			<text class="title">剩余赠送VIP数量:{{vip_num}}</text>
			<view class="title" v-if="parentUser">推荐人：{{parentUser.userName}}</view>
			<view class="head-row">
				<view class="row-wrap">
					<view class="num">{{userInfo.sale_credit || 0}}</view>
					<view class="">个人消费积分</view>
				</view>
				<view class="row-wrap">
					<view class="num">{{userInfo.team_sale || 0}}</view>
					<view class="">团队消费积分</view>
				</view>
				<view class="row-wrap">
					<view class="num">{{userInfo.team_award || 0}}</view>
					<view class="">团队奖金</view>
				</view>
			</view>
		</view>

		<view class="teams-tab">
			<view :class="['tabs',tabIndex == 1?'tab-act':'']" @click="setTabs(1)">
				<view>直推</view>
				<view  :class="['after']"></view>
			</view>
			<view :class="['tabs',tabIndex == 2?'tab-act':'']" @click="setTabs(2)">
				<view>间推</view>
				<view class="after"></view>
			</view>
		</view>
		<view class="teams-ul" v-if="showTeamArr.length > 0">
			<view class="teams-li" v-for="(obj,k) in showTeamArr" :key="k">
				<view class="left">
					<image src="/static/missing-face.png" class="user-icon" mode=""></image>
				</view>
				<view class="right">
					<view class="r-name">
						<view class="name">{{obj.userPhone}}</view>
						<view>{{obj.createTime}}</view>
					</view>
					<view class="r-btn">
						<view class="g-btn sm-btn">{{obj.rankName}}</view>
						<view class="y-btn sm-btn" v-if="obj.abonusName">{{obj.abonusName}}代理</view>
						<view class="b-btn sm-btn">团队：{{obj.team_count || 0}}</view>
            <view class="f-btn sm-btn">{{obj.identity}}</view>
					</view>
				</view>
			</view>
		</view>
		
		<view class="no-ul" v-else>
			--暂无更多数据--
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				userHeadPic: '',
				teams: [],
				userlist: [],
				vip_num: '',
				hasRight: false,
				type: 2,
				vipurl: '',
				shopurl: '',
				parentUser: {},
				tabIndex: 1,
				teamsArr: [],
				indirectArr: [],
				showTeamArr: [],
				userInfo: {},
			}
		},

		onLoad(options) {
			if (options.userImg) {
				this.userHeadPic = options.userImg
				// this.loadTeam()
			}
			this.getvipinfo();
			if(uni.getStorageSync('userDetail')){
				this.userInfo = uni.getStorageSync('userDetail')
				// console.log(JSON.stringify(this.userInfo))
			}
			if (uni.getStorageSync('userDetail').parentUser) {
				this.parentUser = uni.getStorageSync('userDetail').parentUser
			}
		},
		methods: {
			// 切换tab栏
			setTabs(index){
				this.tabIndex = index;
				this.showTeamArr = index == 1?this.teamsArr : this.indirectArr;
			},
			upgrade(item) {
				let that = this;
				var isdisbale = item.canUpgrade;
				let data = {
					userId: item.userId,
					type: 2
				}
				that.$Request.request('api/user_center/doGive', 'POST', data).then(res => {
					if (res.status == 1) {
						that.$api.msg(res.msg || '升级成功');
						that.getvipinfo()
					}
				}).catch(err => {
					console.log(err)
				})
			},
			getvipinfo() {
				let that = this;
				that.$Request.request('/api/Usercentinfo/getSubordinate', 'GET', {}).then(res => {
					if (res.status == 1) {
						this.indirectArr = res.data.jiantui_list;
						this.teamsArr = res.data.list;
						this.showTeamArr = this.teamsArr;
						// that.teams = res.data.list;
						// that.vip_num = res.data.vip_num;
						// that.hasRight = res.data.hasRight
					}
				}).catch(err => {
					console.log(err)
				})
			},
			loadTeam() {
				let that = this
				that.$Request.request('/api/Usercentinfo/getSubordinate', 'GET', {}).then(res => {
					if (res.status == 1) {
						that.teams = res.data.list
					}
				}).catch(err => {
					console.log(err)
				})
			}
		},
	}
</script>

<style>
	page {
		height: 100%;
		background-color: #F8F8F8;
	}
</style>

<style lang="scss" scoped>
	

	.lvup_disbale {
		background-color: #999999;
		color: #fff;
		position: absolute;
		right: 0;
		transform: translateY(-50%);
		top: 50%;
		font-size: 24upx;
		border-radius: 5px;
		width: 130upx;
		height: 40upx;
		line-height: 40upx;
		text-align: center;
	}

	.lvup {
		position: absolute;
		right: 0;
		transform: translateY(-50%);
		top: 50%;
		background-color: #ff6600;
		color: #fff;
		font-size: 24upx;
		border-radius: 5px;
		width: 130upx;
		height: 40upx;
		line-height: 40upx;
		text-align: center;
	}

	.head {
		width: 100%;
		height: 500rpx;
		background-image: url(../static/images/treeBg.png);
		background-size: 100% 100%;
		background-repeat: no-repeat;
		@extend %flexAlCenter;
		flex-direction: column;

		.title {
			font-size: 14px;
			margin-bottom: 10px;
			color: #fff;
		}

		.portrait {
			width: 130upx;
			height: 130upx;
			border: 5upx solid #fff;
			border-radius: 50%;
			margin-bottom: 12rpx;
		}
		
		.head-row {
			width: 100%;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 0px 40rpx;
			box-sizing: border-box;
			.row-wrap {
				text-align: center;
				color: #fff;
				font-size: 28rpx;
				.num {
					line-height: 44rpx;
					font-weight: 600;
				}
			}
		}
	}

	.teamsCon {
		border-radius: 10rpx;
		box-shadow: 0 0 5rpx rgba(0, 0, 0, 0.4);
		margin: 30rpx auto;
		background-color: #fff;
		width: 720rpx;
		color: #999999;
		font-size: $uni-font-size-base;
		// @extend %flexBetw;
		padding: 26rpx;
		display: flex;

		.teamImg {
			width: 150rpx;
			height: 150rpx;
			border-radius: 8rpx;
		}

		.context {
			height: 150rpx;
			width: 75%;
			position: relative;
			// @extend %flexVerticalBetw;

			.firsrLab {
				margin-left: 10px;
				height: 100%;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
			}
		}
	}
	
	.teams-tab {
		width: 100%;
		margin-top: 40rpx;
		display: grid;
		grid-template-columns: 1fr 1fr;
		padding: 0px 32rpx;
		box-sizing: border-box;
		.tabs {
			text-align: center;
			font-size: 32rpx;
			color: #1D1E22;
			line-height: 44rpx;
			display: flex;
			flex-direction: column;
			align-items: center;
			.after {
				width: 192rpx;
				height: 4rpx;
				background: #EE486C;
				margin-top: 14rpx;
				opacity: 0;
			}
		}
		.tab-act {
			color: #EE486C;
			.after {
				opacity: 1;
			}
		}
	}
	
	.teams-ul {
		padding: 12rpx 32rpx;
		box-sizing: border-box;
		.teams-li {
			padding: 32rpx 0rpx;
			width: 100%;
			display: flex;
			align-items: center;
			border-bottom: 2rpx solid #EDEDED;
			.left {
				margin-right: 24rpx;
				.user-icon {
					width: 96rpx;
					height: 96rpx;
					border-radius: 50%;
				}
			}
			.right {
				width: calc(100% - 120rpx);
				.r-name {
					display: flex;
					align-items: center;
					justify-content: space-between;
					font-size: 24rpx;
					color: #7A7C80;
					margin-bottom: 14rpx;
					.name {
						font-size: 32rpx;
						color: #1D1E22;
						line-height: 44rpx;
					}
				}
				
				.r-btn {
					display: flex;
					align-items: center;
					.sm-btn {
						padding: 4rpx 10rpx;
						border-radius: 6rpx;
						margin-right: 12rpx;
						font-size: 20rpx;
						color: #1D1E22;
						line-height: 28rpx;
					}
					.g-btn {
						background: #FF946D;
					}
					.y-btn {
						background: #FFC329;
					}
					.b-btn {
						background: #B58BFF;
					}
          .f-btn {
            background: #4caf50;
          }
				}
			}
		}
	}
	
	
	.no-ul {
		padding: 200rpx 80rpx;
		text-align: center;
		box-sizing: border-box;
		font-size: 28rpx;
		color: #7A7C80;
	}
</style>
